package com.jinke.uang.base;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;

import com.jinke.uang.AppApplication;
import com.jinke.uang.interfaces.ILoading;

import java.util.Locale;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

//   activity最大基类
public abstract class BaseActivity extends AppCompatActivity {
    public AppApplication mApplication;

    public ILoading mLoading;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        initLocaleLanguage();//选择语音资源
        super.onCreate(savedInstanceState);
        mApplication = (AppApplication) getApplication();
        mLoading = createLoadingView();
    }

    protected abstract ILoading createLoadingView();

    //获取layoutId
    protected abstract int getResId();

    public void showLoadingView() {
        if (mLoading != null && !mLoading.isShowing()) {
            mLoading.showLoading();
        }
    }

    public void dismissLoadingView() {
        if (mLoading != null && mLoading.isShowing()) {
            mLoading.dismissLoading();
        }
    }

    /**
     * 选择语言资源
     */
    private void initLocaleLanguage() {
        Resources resources = getApplicationContext().getResources();
        Configuration configuration = resources.getConfiguration();
        configuration.locale = new Locale(Locale.getDefault().getLanguage());
        resources.updateConfiguration(configuration, resources.getDisplayMetrics());//更新配置
    }
}
